/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.component.support.web.upload;

import java.io.File;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.jinhe.tss.core.util.FileHelper;

/**
 * <p> AssuredFilePathCreator.java </p>
 * <p>
 * 将上传文件复制到指定目录
 * </p>
 */
public class FileCopyProcessor implements IFileUploadProcessor {

    @Autowired private IFilePathCreator filePathCreator; // 文件路径生成器

    public File execute(File file, Map<String, String> params) {
        //生成目标文件路径
        FileHelper.createDir(filePathCreator.getPath(file, params));
        File targetFile = new File(filePathCreator.getFullFileName(file, params));
        
        //文件复制
        String targetPath = targetFile.getParent();
        String fileName = FileHelper.copyFile(new File(targetPath), file, true, false);
        new File(targetPath + "/" + fileName).renameTo(targetFile);
        
        return targetFile;
    }

}
